import React, {PureComponent} from 'react';
import {Form, Input, Modal, Select, Steps,} from 'antd';
import DescriptionList from '@/components/DescriptionList';
import {ruleP, nameMaxLength,remarkMaxLength} from '@/utils/rule'
const {Description} = DescriptionList;
const FormItem = Form.Item;
const {Step} = Steps;
const {TextArea} = Input;
const {Option} = Select;

@Form.create()
class CreateOrUpdateDirForm extends PureComponent {


  render() {
    const {modalVisible, form, addOrUpdateDir, handleModalVisible, record} = this.props;
    const okHandle = () => {
      form.validateFields((err, fieldsValue) => {
        if (err) return;
        addOrUpdateDir(fieldsValue, record);
      });
    };

    let title = "";
    if (record && record.id) {
      //文件夹
      title = "重命名";
    }else{
      title = "新建";
    }

    return (
      <Modal
        destroyOnClose
        title={title}
        visible={modalVisible}
        onOk={okHandle}
        onCancel={() => handleModalVisible()}
        maskClosable={false}
      >
        <FormItem labelCol={{span: 5}} wrapperCol={{span: 18}} label="名称">
          {form.getFieldDecorator('dirName', {
            rules: [{ required: true, message: '名称不能为空'},
              {pattern:new RegExp(ruleP(6)[0],'g'), message:ruleP(6)[1]},
              {max:nameMaxLength()[0],message:nameMaxLength()[1]}],
            initialValue: record.dirName || "",
          })(<Input placeholder="请输入"/>)}
        </FormItem>
      </Modal>
    );
  }
}

export default CreateOrUpdateDirForm;
